clear all
cd "D:\Taylor_JAERE_2020_DONE"
use TxnDATA_53stores_SumStat

*********************************************************************************************************************
										************************ 
										*  Summary Statistics
										************************
*********************************************************************************************************************
 	
	*) Store Characteristics
			 preserve

			 collapse (mean) building_size open_date remodel_date st_bakery st_cust_serve ///
							st_pharm st_deli st_floral st_coffee st_has_self_check st_gas st_juice ///
							st_sandwich MedInc HHSizeAverage white black asian over65 noVehicle urban, by(store_id TREAT)	
							
					label variable st_bakery "Bakery Dept."
					label variable st_cust_serve "Customer Service"
					label variable st_pharm "Pharmacy"
					label variable st_deli "Deli Dept."
					label variable st_floral "Floral Dept."
					label variable st_coffee "Coffee Bar"		
					label variable st_has_self_check "Self-checkout"
					label variable st_gas "Gas Station"
					label variable st_juice "Juice Bar"
					label variable st_sandwich "Sandwich Counter"	
					label variable remodel_date "Remodel Date"
					label variable open_date "Open Date"
					label variable building_size "Building Size"
					label variable MedInc "Median Income"
					label variable HHSizeAverage "Household Size"
					label variable white "White"
					label variable black "Black"
					label variable asian "Asian"
					label variable over65 "Over 65"
					label variable noVehicle "Do not own vehicle"
					label variable urban "Urban"					

				* Table 1 *	
				estpost ttest building_size open_date remodel_date st_bakery ///
							st_pharm st_deli st_floral st_coffee st_gas st_juice ///
							st_sandwich st_has_self_check MedInc HHSizeAverage white black asian over65 noVehicle urban,  by(TREAT) 
				estimates store store_charact_balance	
				esttab store_charact_balance using ${latex}store_charact_balance.tex, ///
				cells("mu_1(fmt(%12.2fc) label(Control)) mu_2(fmt(%12.2fc) label(Treat)) p(fmt(3) label(P-value of Diff) star)") ///
				nonotes replace noobs star(* 0.10 ** 0.05 *** 0.01)  label nonumbers alignment(ccc) gaps width(\hsize) 
			restore			
	
		egen city_clust = group(store_city)
		egen week_group = group(promo_week_id)
	
	*) Transaction-level characteristics	
		preserve
			 keep if year == 2011
			 
			 replace tot_scan = . if txn_mins ==.
			 replace expenditure_paid = . if txn_mins ==.
			 			 
			 collapse (mean) txn_mins tot_scan expenditure_paid, ///
							 by(store_id TREAT city_clust week_group)
			 		 
				* Table 2 *	
				estpost ttest txn_mins tot_scan expenditure_paid, by(TREAT) 	
				estimates store txn_balance								
				esttab txn_balance using ${latex}txn_balance.tex, ///
				cells("mu_1(fmt(%12.2fc) label(Control)) mu_2(fmt(%12.2fc) label(Treat)) p(fmt(3) label(P-value of Diff.) star)") ///
				nonotes replace noobs star(* 0.10 ** 0.05 *** 0.01)  label nonumbers alignment(ccc) 
					
				reghdfe txn_mins TREAT, noabsorb vce(cluster city_clust week_group)	
				reghdfe tot_scan TREAT, noabsorb vce(cluster city_clust week_group)
				reghdfe expenditure_paid TREAT, noabsorb vce(cluster city_clust week_group)		
				tab TREAT
			restore	
					
	*) Store-shift characteristics	
		preserve
			 keep if year == 2011

			 replace tot_scan = . if txn_mins ==.
			 replace expenditure_paid = . if txn_mins == .
			 	 
			 keep store_day_TRANS store_id TREAT year month day st_has_self_check promo_week_id ///
						 expenditure_paid tot_scan city_clust week_group total_count total_open
			 
			 collapse (mean) store_day_TRANS  ///
							(sum) expenditure_paid tot_scan ///
							(max) total_open total_count, ///
								by(store_id TREAT year month day promo_week_id st_has_self_check city_clust week_group)	
								
			* Table 2 *						
			 collapse (mean) store_day_TRANS  ///
							(mean) expenditure_paid tot_scan ///
							(mean) total_count total_open , ///
								by(store_id TREAT st_has_self_check city_clust week_group)			 
			 	 
				estpost ttest store_day_TRANS expenditure_paid  tot_scan total_open total_count,  by(TREAT)	
				estimates store TRANS_balance								
				esttab TRANS_balance using ${latex}shift_balance.tex, ///
				cells("mu_1(fmt(%12.2fc) label(Control)) mu_2(fmt(%12.2fc) label(Treat)) p(fmt(3) label(P-value of Diff.) star)") ///
				nonotes replace noobs star(* 0.10 ** 0.05 *** 0.01)  label nonumbers alignment(ccc)  		 						

				reghdfe store_day_TRANS TREAT, noabsorb vce(cluster city_clust week_group)	
				reghdfe expenditure_paid TREAT, noabsorb vce(cluster city_clust week_group)
				reghdfe tot_scan TREAT, noabsorb vce(cluster city_clust week_group)		
				reghdfe total_open TREAT, noabsorb vce(cluster city_clust week_group)
				reghdfe total_count TREAT, noabsorb vce(cluster city_clust week_group)		
				tab TREAT
			restore				
		